//
//  MQmanager.h
//  YKRabbitMQSDK
//
//  Created by edward on 2020/6/14.
//  Copyright © 2020 edward. All rights reserved.
//



#import "MQKey.h"
NS_ASSUME_NONNULL_BEGIN

#define MQManager_Installed

typedef NS_ENUM(NSInteger, MQManagerRecoveredType) {
    MQManagerRecoveredTypeFinish                 = 0,///已经恢复连接
    MQManagerRecoveredTypeWillStart,///正在恢复连接
    MQManagerRecoveredTypeStarting,///开始恢复连接
};

typedef NS_ENUM(NSInteger, MQManagerErrorType) {
    MQManagerErrorTypeConnectAbnormal                  = 0,///连接过程通道异常
    MQManagerErrorTypeConnectFaild,///没有连接成功回调
    MQManagerErrorTypeOverTimeOrAddressError,///socket连接失败
};

@class MQManager;

@protocol MQManagerDelegate <NSObject>

@required

//收到消息
- (void)mqmanager:(MQManager *)manager receiveMessageData:(NSData *)receiveMessageData routingKey:(NSString *)routingKey consumerTag:(NSString *)consumerTag exchangeName:(NSString *)exchangeName receiveDate:(NSString *)receiveDate;

//错误回调
- (void)mqmanager:(MQManager *)manager onError:(NSError *)error errorType:(MQManagerErrorType)errorType;

@optional
//恢复连接
- (void)mqmanager:(MQManager *)manager recoveredConnectionType:(MQManagerRecoveredType)recoveredConnectionType;

@end

@interface MQManager : NSObject

/**创建组件*/
- (instancetype)init NS_UNAVAILABLE;

/// 登录mq
/// @param user 用户名
/// @param password 密码
/// @param path mq地址
/// @param exchangeNames 交换机名字（可多个）
/// @param routingKeys 路由名
/// @param delegate 代理
+ (instancetype)loginUser:(NSString *)user password:(NSString *)password path:(NSString *)path exchangeNames:(NSArray<NSString *> *)exchangeNames routingKeys:(NSArray<MQKey *> *)routingKeys delegate:(id<MQManagerDelegate>)delegate;

/**使用guest默认游客登录mq*/
+ (instancetype)loginPath:(NSString *)path exchangeNames:(NSArray<NSString *> *)exchangeNames routingKeys:(NSArray<MQKey *> *)routingKeys delegate:(id<MQManagerDelegate>)delegate;

/**默认使用单一exchangeName*/
+ (instancetype)loginUser:(NSString *)user password:(NSString *)password path:(NSString *)path routingKeys:(NSArray<MQKey *> *)routingKeys delegate:(id<MQManagerDelegate>)delegate;

/**默认使用游客以及单一exchangeName（最轻量）*/
+ (instancetype)loginPath:(NSString *)path routingKeys:(NSArray<MQKey *> *)routingKeys delegate:(id<MQManagerDelegate>)delegate;

/**接收数据(示例方法)*/
- (void)getMsg;

/**MQ是否为关闭状态*/
- (BOOL)mqIsClosd;

/**向队列发送消息 使用默认的交换机*/
- (void)sendNorMsg:(NSString *)msg key:(MQKey *)key;

/**向队列发送消息*/
- (void)sendMsg:(NSString *)msg exchangeName:(NSString *)exchangeName AndKey:(MQKey *)key;

/**主动断开MQ链接*/
- (void)endConnection;

@end

NS_ASSUME_NONNULL_END
